﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

//http://msdn.microsoft.com/en-us/library/aa302326.aspx
namespace WebFabricator.org.Management
{
    [Serializable]
    [DefaultPropertyAttribute("Machine")]
    public class HELOResult
    {

        [CategoryAttribute("Infrastructure"),
        DescriptionAttribute("WINS Machine Name"),
        ReadOnly(true)]
        public string Machine
        {
            get;
            set;
        }


        [CategoryAttribute("Topology"),
        DescriptionAttribute("Role of machine"),
        ReadOnly(true)]
        public string Designation
        {
            get;
            set;
        }

        [CategoryAttribute("Application"),
        DescriptionAttribute("List of Local Store instances running on machine"),
        ReadOnly(true)]
        public string[] Instances
        {
            get;
            set;
        }

        public override string  ToString()
        {
            return String.Join(";", new[] { Machine, Designation, string.Join(",",Instances)});
        }

        public static HELOResult Parse(string data)
        { 
            HELOResult result = new HELOResult();
            int i = 0;
            Array.ForEach(data.Split(';'), (s) => {
                switch (i)
                { 
                    case 0:
                        result.Machine = s;
                        break;
                    case 1:
                        result.Designation = s;
                        break;
                    case 2:
                        result.Instances = s.Split(',');
                        break;
                    default: 
                        throw new NotSupportedException();
                }
                i++;
            });
            return result;
        }

    }
}
